<!--
 * @Description: 所有课程更多-course
 * @Author: your name
 * @Date: 2023-12-06
 * @LastEditTime: 2023-12-06
 * @LastEditors: Please set LastEditors
-->

<template>
  <div class="layout heart_w">
    <div class="container">
      <div class="course_item">
        <div class="course_title">
          <span>科目：</span>
        </div>
        <div class="content_list">
          <div
            v-for="(item, index) in courseList"
            :key="item.id"
            @click="classify(1, index, item)"
          >
            <span :class="index_class == index ? 'on' : ''">
              {{ item.name }}
            </span>
          </div>
        </div>
      </div>

      <div class="course_item">
        <div class="course_title">
          <span>级别：</span>
        </div>
        <div :class="{ content_list: true, autoHeight: class_val }">
          <div
            v-for="(item, index) in LevelList"
            :key="item.id"
            @click="SecondaryClass(index, item)"
          >
            <span :class="{ on: index_t == index }">{{ item.name }}</span>
          </div>
        </div>

        <div
          class="item_morethan"
          @click="classifyState"
          v-if="LevelList.length > 16"
        >
          <span>更多</span> <i class="el-icon-arrow-up" v-if="class_val"></i>
          <i class="el-icon-arrow-down" v-else></i>
        </div>
      </div>

      <div class="course_item">
        <div class="course_title">
          <span>推荐排序：</span>
        </div>
        <div class="content_list">
          <div
            v-for="(item, index) in orderedList"
            :key="item.id"
            @click="classify(2, index, item)"
          >
            <span :class="sort_index == index ? 'on' : ''">
              {{ item.name }}
            </span>
          </div>
        </div>
      </div>
    </div>

    <!-- 内容区域 -->
    <div class="curriculum_list">
      <div class="recommend heart_w">
        <el-row>
          <el-col :span="6" v-for="item in courseDataArr" :key="item.id">
            <a href="javascript:void(0)" @click="course_list(item.id)">
              <el-image lazy :src="item.image"> </el-image>
              <div>
                <div class="title" :title="item.title">
                  {{ item.title }}
                </div>
                <div class="browse-money"></div>
                <div class="label-count">
                  <div>{{ item.buy_nums }}人已购买</div>
                  <div class="money">
                    ￥
                    <span>{{ item.price }}</span>
                  </div>
                </div>
              </div>
            </a>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getCateList,
  getLevelList,
  getSortList,
  getComboList
} from '@/api/course.js'
export default {
  name: 'courseKC',
  data() {
    return {
      index_t: 0,
      index_class: 0,
      sort_index: 0,
      class_val: false,
      cate_id: '', // 科目
      level_id: '', // 级别
      sort_id: '', // 排序
      courseList: [], // 科目列表
      LevelList: [], // 级别
      orderedList: [], // 排序
      courseDataArr: []
    }
  },
  created() {
    this.getDataList()
    this.getSortOrderData()
    this.ComboList()
    console.log(this.$route)
  },
  methods: {
    getDataList() {
      getCateList().then(({ data: data }) => {
        this.courseList = data.data
      })
      getLevelList().then(({ data: data_l }) => {
        this.LevelList = data_l.data
      })
    },
    getSortOrderData() {
      getSortList().then(({ data: data_p }) => {
        this.orderedList = data_p.data
      })
    },
    ComboList() {
      let data_l = {
        cate_id: this.cate_id,
        level_id: this.level_id,
        sort_id: this.sort_id,
        page: 1
      }
      getComboList(data_l).then(({ data: data }) => {
        this.courseDataArr = data.data.list
        console.log(data.data.list)
      })
    },
    SecondaryClass(i, item) {
      this.index_t = i
      this.level_id = item.id

      this.ComboList()
      console.log(item.id)
    },
    classify(val, index, it) {
      if (val == 1) {
        this.index_class = index
        this.cate_id = it.id
        this.ComboList()
        console.log(it.id)
      } else if (val == 2) {
        this.sort_id = it.id
        this.sort_index = index
        this.ComboList()
        console.log(it.id, 222)
      }
    },
    classifyState() {
      this.class_val = !this.class_val
    },
    course_list(idt) {
      this.$router.push({ path: '/handpick_kc', query: { id: idt } })
    }
  }
}
</script>

<style scoped lang="scss">
.on {
  color: #2c8eff;
  font-weight: bold;
}

.autoHeight {
  height: auto !important;
}

.layout {
  margin-top: 30px;
}

.container {
  padding: 10px 20px 0 17px;
  border-radius: 4px;
  background-color: #ffffff;
}
.course_item {
  display: flex;
  align-items: center;

  .course_title {
    font-size: 14px;
    line-height: 60px;
    color: #969696;
  }
}

.content_list {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
  height: 60px;
  padding: 15px 103px 0 33px;
  box-sizing: border-box;
  overflow: hidden;
  border-bottom: 1px dashed #efefef;

  .content_item {
    img {
      width: 10px;
      height: 14px;
      margin: 0 0 0 10px;
      vertical-align: middle;
      cursor: pointer;
      user-select: none;
    }
  }

  div {
    height: 30px;
    margin-right: 30px;
    margin-bottom: 15px;
    line-height: 30px;
    font-size: 14px;
    color: #282828;

    span {
      cursor: pointer;
      user-select: none;
    }
  }
}

.item_morethan {
  height: 30px;
  margin: 15px 0;
  font-size: 14px;
  line-height: 30px;
  color: #282828;
  user-select: none;
  cursor: pointer;
}

.recommend {
  padding-bottom: 30px;
  .el-col {
    margin-bottom: 14px;
    padding: 0 7px;
  }
  .el-col-6 {
    padding: 0 7px;
  }
  .el-row {
    margin-top: 30px;
    a {
      display: block;
      border-radius: 8px;
      background-color: #fff;
      overflow: hidden;
      transition: 0.3s;

      .el-image {
        display: block;
        width: 100%;
        height: 160px;
        position: relative;

        .type {
          position: absolute;
          right: 7px;
          bottom: 7px;
          z-index: 2;
          width: 20px;
          height: 20px;
          padding: 4px;
          border-radius: 50%;
          background-color: rgba(0, 0, 0, 0.5);
        }
      }

      .el-image + div {
        padding: 0 15px;
      }
    }
  }

  .el-row a:hover {
    // transform: translateY(-6px);
    box-shadow: 0px 2px 15px rgb(79 109 143 / 15%);
  }

  .label-count {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 48px;
    border-top: 1px dashed #eee;
    font-size: 14px;
    color: #999;

    .money {
      font-size: 14px;
      color: #ff6b00;
      span {
        font-size: 18px;
      }
    }
  }

  .browse-money {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    color: #666;

    .el-tag {
      height: 22px;
      padding-right: 9px;
      padding-left: 9px;
      border-color: rgba(44, 142, 255, 0.06);
      border-radius: 2px;
      background-color: rgba(44, 142, 255, 0.06);
      line-height: 20px;
      color: #2c8eff;
    }
  }

  .title {
    padding-top: 15px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 16px;
    color: #333;
  }
}
</style>
